package com.example.tushu.Controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.tushu.Pojo.JsonResult;
import com.example.tushu.Pojo.User;
import com.example.tushu.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Objects;

@RestController
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public JsonResult login(@RequestBody User user){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_acc", user.getUserAcc());
        if (userService.count(wrapper) == 0)
            return new JsonResult(500,"没有该账号");
        User user1=userService.getOne(wrapper);
        if (!Objects.equals(user1.getUserPwd(), user.getUserPwd()))
            return new JsonResult(500,"密码错误");
        return new JsonResult("登陆成功", user1);
    }
}
